package cn.uo86.mail.service;

import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import cn.uo86.mail.db.DbHelper;
import cn.uo86.mail.db.Tab_Info;
import cn.uo86.mail.domain.MailInfo;

public class MailInfoServiceTest {
	private DbHelper dbInstance;

	public MailInfoServiceTest(Context context) {
		this.dbInstance = new DbHelper(context);
	}
	public void save(MailInfo info){
		SQLiteDatabase db = dbInstance.getWritableDatabase();
		db.execSQL("INSERT INTO " +
				Tab_Info.TB_MAIL +
				"(" +Tab_Info.NAME+
				"," +Tab_Info.URL+
				"," +Tab_Info.SEQ+
				"," +Tab_Info.ISSELECTED+
				"," +Tab_Info.ISMAIN+
				") "+"values(?,?,?,?,?)", new Object[]{info.getName(),info.getUrl(),info.getSeq(),info.isSelected(),info.isMain()});
		db.close();
	}
	public void delete(Integer Id){
		SQLiteDatabase db = dbInstance.getWritableDatabase();
		db.delete(Tab_Info.TB_MAIL, "id = ?", new String[]{String.valueOf(Id)});
		db.close();
	}
	public void update(MailInfo info ,Integer Id){
		SQLiteDatabase db = dbInstance.getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put(Tab_Info.NAME, info.getName());
		values.put(Tab_Info.URL, info.getUrl());
		values.put(Tab_Info.SEQ, info.getSeq());
		values.put(Tab_Info.ISSELECTED, info.isSelected());
		values.put(Tab_Info.ISMAIN, info.isMain());
		db.update(Tab_Info.TB_MAIL, values, "id = ?", new String[]{String.valueOf(Id)});
	}
	public List<MailInfo> query(Object[] objects){
		SQLiteDatabase db = dbInstance.getReadableDatabase();
//		db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy)
		return null;
	}
}
